package com.example.task1.ui.AllService.law;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.base.BaseActivity;
import com.example.task1.bean.LawOrderDetailBean;
import com.example.task1.http.Api;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;

import java.util.HashMap;

import retrofit2.Call;

public class LawOrderDetailActivity extends BaseActivity {

    private int id;
    private TextView tvName;
    private TextView tvContent;
    private TextView tvPhone;
    private TextView tvTime;
    private EditText etInput;
    private Button btnSend;
    private EditText etScore;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_law_order_detail);
        id = getIntent().getIntExtra("id", 0);
        initData();
        initView();
        business();
    }

    private void business() {
        btnSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String content = etInput.getText().toString();
                String score = etScore.getText().toString();
                if (TextUtils.isEmpty(content)) {
                    etInput.setError("不能为空");
                } else if (TextUtils.isEmpty(score)) {
                    etScore.setError("不能为空");
                } else {
                    HashMap<String, Object> map = new HashMap<>();
                    map.put("id", id);
                    map.put("evaluate", content);
                    map.put("score", score);
                    Call<ApiResp> post = Api.api().post(MyApplication.TOKEN, "/prod-api/api/lawyer-consultation/legal-advice/evaluate", Api.getBody(map));
                    Api.send(post, ApiResp.class, new CallBack<ApiResp>() {
                        @Override
                        public void success(ApiResp data) {
                            MyApplication.show("评价成功");
                        }

                        @Override
                        public void error(String msg) {

                        }
                    });

                }
            }
        });
    }

    private void initData() {
        Call<ApiResp> call = Api.api().get(MyApplication.TOKEN, "/prod-api/api/lawyer-consultation/legal-advice/" + id);
        Api.send(call, LawOrderDetailBean.class, new CallBack<LawOrderDetailBean>() {
            @Override
            public void success(LawOrderDetailBean data) {
                LawOrderDetailBean.DataDTO date = data.getData();
                tvName.setText(date.getLawyerName());
                tvContent.setText(date.getContent());
                tvPhone.setText(date.getPhone());
                tvTime.setText(date.getCreateTime());
            }

            @Override
            public void error(String msg) {

            }
        });
    }

    @Override
    public String getMyTitle() {
        return "详情";
    }

    private void initView() {
        tvName = findViewById(R.id.tv_name);
        tvContent = findViewById(R.id.tv_content);
        tvPhone = findViewById(R.id.tv_phone);
        tvTime = findViewById(R.id.tv_time);
        etInput = findViewById(R.id.et_input);
        btnSend = findViewById(R.id.btn_send);
        etScore = findViewById(R.id.et_score);
    }
}